package com.manager;

import java.lang.ref.WeakReference;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;

import com.example.quest.R;
import com.game.activity.MainActivity;
import com.game.activity.pager.MainPagerAdapter;

public class UIHandler extends Handler {
	
	private final WeakReference<MainActivity> mainActivity;
	
	public UIHandler(MainActivity mainActivity) {
		this.mainActivity = new WeakReference<MainActivity>(mainActivity);
	}
	
	@Override
	public void handleMessage(Message msg) {
		MainActivity mainActivity = this.mainActivity.get();
		
		Bundle bundle = msg.getData();
		MessageType msgType = (MessageType) bundle.getSerializable("msg");
		
		switch (msgType) {
		case MESSAGE_INIT_MAIN:
			mainActivity.setContentView(R.layout.activity_menu_main);
			mainActivity.mainAdapter = new MainPagerAdapter();
			mainActivity.mainPager = (ViewPager) mainActivity.findViewById(R.id.panelpager);
			mainActivity.mainPager.setAdapter(mainActivity.mainAdapter);
			mainActivity.mainPager.setCurrentItem(3);
			break;
			
		case MESSAGE_INIT_CREATION:
			mainActivity.setContentView(R.layout.activity_creation_name_gender);
			break;
			
		default:
			break;
		}
	}
}
